#ifndef OCTREE_NODE_H
#define OCTREE_NODE_H

#include "vector3d.h"
#include "object.h"
#include "defines/octreeType.h"
#include <iostream>
#include <stack>

class OctreeNode{
    public:
        OctreeNode(int = 0, int = -1, OctreeNode * = NULL, unsigned int = GREY);
        OctreeNode(const OctreeNode &, OctreeNode *, bool = false);
        ~OctreeNode();

        unsigned int getType() const;
        int getDepth() const;
        int getPosition() const;
        void setPosition(int);
        OctreeNode *getParent() const;
        OctreeNode *getNode(int) const;
        void setNode(int, OctreeNode *);

        void getAllPoints(Vector3D *, const Vector3D &, const Vector3D &);
        void getChildMinMax(int, Vector3D *, Vector3D *, Vector3D *) const;
        void createStatic(char);
        void create(Object *, int, const Vector3D &, const Vector3D &);

        void draw(bool, bool, Color, const Vector3D &, const Vector3D &);
        void drawNode(bool, Color, Vector3D *);

        double volume() const;
        double area();
        void rotate(int, int, int);

    private:
//        Vector3D min, max;
        int depth;
        int position;
        OctreeNode *parent;
        unsigned int type;
        OctreeNode **node;


        double getWhiteNeighbours(int, std::stack<int>);
        double getWhiteChildUp(int, std::stack<int>);
        double getWhiteChildDown(int, std::stack<int>);
        double getWhiteChildRight(int, std::stack<int>);
        double getWhiteChildLeft(int, std::stack<int>);
        double getWhiteChildFront(int, std::stack<int>);
        double getWhiteChildBack(int, std::stack<int>);
        double getWhiteNeighboursUp(int, std::stack<int>);
        double getWhiteNeighboursDown(int, std::stack<int>);
        double getWhiteNeighboursRight(int, std::stack<int>);
        double getWhiteNeighboursLeft(int, std::stack<int>);
        double getWhiteNeighboursFront(int, std::stack<int>);
        double getWhiteNeighboursBack(int, std::stack<int>);
};

OctreeNode *combine(OctreeNode *, OctreeNode *, int);
OctreeNode *octreeNodeUnion(OctreeNode *, OctreeNode *, OctreeNode * = NULL);
OctreeNode *octreeNodeIntersection(OctreeNode *, OctreeNode *, OctreeNode * = NULL);
OctreeNode *octreeNodeDifference(OctreeNode *, OctreeNode *, OctreeNode * = NULL);

#endif


